package getinfo;

import java.net.URLDecoder;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

/**
 * @author qhy
 * @version 1.0.0
 * @ClassName GetRegionServerInfo
 * @Description TODO
 * @Date 2017/6/30 9:10
 */
public class GetRegionServerInfo {

    public String sendQuquestByGet(String url){
        String result = "";

        try {
            DefaultHttpClient client = new DefaultHttpClient();
            //发送get请求
            HttpGet request = new HttpGet(url);
            HttpResponse response = client.execute(request);

            if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
            {
                result = EntityUtils.toString(response.getEntity());
                url = URLDecoder.decode(url,"UTF-8");
            }else{
                System.out.println("提交get请求失败------------------1");
            }
        }catch(Exception e){
            e.printStackTrace();
            System.out.println("提交get请求失败------------------2");
        }
        return result;
    }

    public void sendQequestByPost(String url){
        //post请求返回结果
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost method = new HttpPost(url);

    }

    public static void main(String[] args){
        GetRegionServerInfo getInfo = new GetRegionServerInfo();
        System.out.println(getInfo.sendQuquestByGet("http://192.168.0.41:8080/status/cluster"));
    }
}
